package com.moyun.zbmy.zizhou.ui.activities;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.view.View;

import com.moyun.zbmy.zizhou.R;
import com.moyun.zbmy.zizhou.base.BaseActivity;
import com.moyun.zbmy.zizhou.ui.dialog.ShowDiaFragment;
import com.moyun.zbmy.zizhou.ui.utils.TitleUtils;
import com.ruihang.generalibrary.ui.dialog.BaseDialogFragment;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 关于
 */
public class JubaoActivity extends BaseActivity {

    private ShowDiaFragment showDiaFragment;
    public static final String SHOW_TAG = "dia_show_fragment";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new TitleUtils(this).setBackVisible(true).setLogo(false);
        new TitleUtils(this).useAndSetTxTitle("举报途径");




    }

    @Override
    protected void initInject() {
        setContentView(R.layout.activity_jubao);
        ButterKnife.bind(this);
    }


    @OnClick({R.id.tv_url,R.id.tv_phone})
    protected void OnClick(View view) {
        if (view.getId() == R.id.tv_url) {
            Intent intent = new Intent(this, H5NormalActivity.class);
            intent.putExtra(EX_TITLE, "举报");
            intent.putExtra(EX_HTML, "https://www.12377.cn/");
            startActivity(intent);
        }else if (view.getId() == R.id.tv_phone) {
            showDialogOk(3);

        }
    }


    public void showDialogOk(int type) {
//        if (showDiaFragment == null) {
        showDiaFragment = new ShowDiaFragment();
//        }
        showDiaFragment.setCallBack(callBack);
        showDiaFragment.setType(type);
        showDiaFragment.show(getSupportFragmentManager(), SHOW_TAG);
    }

    //Dialog点击回调
    public BaseDialogFragment.ICallBack callBack = new BaseDialogFragment.ICallBack() {
        @Override
        public void onCallBackMsg(BaseDialogFragment fragment, Message msg) {
            parseWhat(msg.what);
        }
    };


    /**
     * 切换字体后回调刷新UI
     *
     * @param what
     */
    private void parseWhat(int what) {
        if (what == ShowDiaFragment.PHONE_TAG_JUBAO) {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + getString(R.string.user_jubaophone)));
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
                toast(R.string.failed_to_phone);
            }
        }
    }

}
